import { Color3, Material, Mesh, Scene } from 'babylonjs';
// @ts-ignore
import MeshWriter from "meshwriter";
export default {
  "font-family": "Arial",
  "letter-height": 0.5, // 高度
  "letter-thickness": 0.01, //  厚度
  color: "#000000",
  anchor: "center",
  colors: {
    diffuse: "#000000",
    specular: "#000000",
    ambient: "#ffffff",
    emissive: "#000000"
  },
}

/**
 * 偏好配置
 */
interface Option {
  /**
   * 字体
   */
  fontFamily?: string,
  /**
   * 字体大小
   */
  letterHeight?: number,
  /**
   * 字体厚度
   */
  letterThickness?: number,
  /**
   * 颜色
   */
  color?: string,
  /**
   * 对齐方式
   */
  anchor?: 'center' | 'left' | 'right',
  /**
   * 其他颜色
   */
  colors?: {
    diffuse?: string,
    specular?: string,
    ambient?: string,
    emissive?: string
  },
  /**
   * 位置
   */
  position?: {
    x?: number
    y?: number
    z?: number
  }
}


// getSPS
//    getMesh
//    getMaterial
//    color                   # sets or gets color but no change to material
//    alpha                   # sets or gets alpha but no change to material
//    setColor                # set emissive color and change color value
//    setAlpha                # change value and material
//    overrideOpac            # change material but not value
//    resetOpac               # sets material to current value
//    dispose

// interface SPS {
//   getMesh: () => Mesh,
//   getMaterial:() => Material,
// }


// SPS.updateParticle = (particle: any) => {
//   particle.rotation.x -= 0.06;
// };
// scene.registerBeforeRender(() => {
//   SPS.setParticles();
// });

/**
 * 创建3D文字
 * @param word 需要渲染的文字（单个字符）
 * @param scene 场景
 * @param option 指定缩放、字体等
 * @param writerOption 偏好配置
 */
export const createText = (
  word: string,
  scene: Scene,
  option?: {
    scale?: number,
    defaultFont?: string
  },
  writerOption?: Option
) => {
  const writer = MeshWriter(scene, option)
  return new writer(word, {
    ...writerOption,
    'letter-height': writerOption?.letterHeight,
    'letter-thickness': writerOption?.letterThickness
  })
}